﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace APH.Parl2.Client.Parl2.DynamicData.DataAnnotations
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class ValuesListAttribute : Attribute
    {
        public ValuesListAttribute() { }

        /// <summary>
        /// Construvtor take a list of values
        /// to show in the ListControl
        /// </summary>
        /// <param name="values">
        /// A ',' or ';' seperated list of values in the order
        /// that they should appear in the list control.
        /// </param>
        public ValuesListAttribute(String values)
        {
            var items = values.Split(new char[] { ',', ';' });
            Values = (from item in items
                      select new ListItem()
                      {
                          Text = item,
                          Value = item
                      }).ToArray();
        }

        public ListItem[] Values { get; set; }
    }
}